/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package services;

import beans.GetBean;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PUT;
import org.json.JSONObject;

/**
 * REST Web Service
 *
 * @author tae
 */
@Path("resource/GetComment")
@Stateless
public class GetCommentResource {

    @Context
    private UriInfo context;
    
    @EJB
    private GetBean getBean;

    /**
     * Creates a new instance of GetPostResource
     */
    public GetCommentResource() {
    }

    @POST
    @Produces("application/json")
    public String execute(@FormParam("channelID") long channelID) {
        System.out.println("GetComment executed" + channelID);
        
        List<Map<String, Object>> comments =  getBean.getComment(channelID);
        
        JSONObject outJSON = new JSONObject();
        
        if(comments.isEmpty())
        {
            outJSON.put("code", "E");
        }
        else
        {
            outJSON.put("code", "T");
        }
        outJSON.put("comment", comments);
        
        return outJSON.toString();
    }
}
